package com.ssm.zhihu_ssm.controller;

import com.ssm.zhihu_ssm.entity.Answer;
import com.ssm.zhihu_ssm.service.AnswerService;
import com.ssm.zhihu_ssm.service.UserService;
import com.ssm.zhihu_ssm.util.ReturnMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class AnswerController {

    @Autowired
    private AnswerService answerService;
    @Autowired
    private UserService userService;

    @RequestMapping("/insertAnswer")//写回答
    public Map<String, Object> insertAnswer(String phone, int question_id, String content){
        int x = userService.findId(phone);
         answerService.insertAnswer(x, question_id, content);
        Map<String, Object> map = ReturnMap.ReturnMapS("true");
        return map;
    }

//    @RequestMapping("/getAnswerByUserId")
//    @ResponseBody
//    public Map<String, Object> getAnswerByUserId(int id){    //根据用户id得到用户的所有回答
//        List<Answer> answerList = answerService.getAnswerByUsrId(id);
//        Map<String, Object> map = ReturnMap.ReturnMapS(answerList);
//        return map;
//    }

    @RequestMapping("/collectAnswer")//用户收藏回答
    public Map<String, Object> collectAnswer(String phone, int answer_id){
        int x = userService.findId(phone);
        answerService.collectAnswer(x, answer_id);
        Map<String, Object> map = ReturnMap.ReturnMapS("true");
        return map;
    }

    @RequestMapping("/addAnswerGoodNumByAnswerId")//给回答点赞
    @ResponseBody
    public Map<String, Object> addAnswerGoodNumByAnswerId(int id, boolean isAdd){
        answerService.addAnswerGoodNumByAnswerId(id, isAdd);
        Map<String, Object> map = ReturnMap.ReturnMapS("true");
        return map;
    }

    @RequestMapping("/addAnswerBadNumByAnswerId")//给回答点踩
    @ResponseBody
    public Map<String, Object> addAnswerBadNumByAnswerId(int id, boolean isAdd){
        answerService.addAnswerBadNumByAnswerId(id, isAdd);
        Map<String, Object> map = ReturnMap.ReturnMapS("true");
        return map;
    }

    @RequestMapping("/getAnswerByAnswerId") //根据回答id得到回答
    @ResponseBody
    public Map<String, Object> getAnswerByAnswerId(int id){
        List<Answer> answerList = answerService.getAnswerByAnswerId(id);
        Map<String, Object> map = ReturnMap.ReturnMapS(answerList);
        return map;
    }

    @RequestMapping("/getAnswerByQuestionId") //根据问题id得到所有回答
    @ResponseBody
    public Map<String, Object> getAnswerByQuestionId(int id){
        List<Answer> answerList = answerService.getAnswerByQuestionId(id);
        Map<String, Object> map = ReturnMap.ReturnMapS(answerList);
        return map;
    }

    @RequestMapping("/getHotSortAnswer")//根据主题id得到所有按点赞排序后的回答
    @ResponseBody
    public Map<String, Object> getHotSortAnswer(int id){
        List<Answer> answerList = answerService.getHotSortAnswer(id);
        Map<String, Object> map = ReturnMap.ReturnMapS(answerList);
        return map;
    }

//    @RequestMapping("/getQuestionAnswerListByAnswerId")
//    @ResponseBody
//    public Map<String, Object> getQuestionAnswerListByAnswerId(int id){   //根据回答id得到 所有该问题的回答
//        List<QuestionAnswerList> questionAnswerList = questionAnswerListService.getQuestionAnswerListByAnswerId(id);
//        System.out.println(questionAnswerList);
//        Map<String, Object> map = ReturnMap.ReturnMapS(questionAnswerList);
//        return map;
//    }


}